package org.example.ding.model;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 每日营养摄入汇总
 */
public class DailyNutritionSummary {
    
    private LocalDate date;
    private BigDecimal totalCalories;
    private BigDecimal totalProtein;
    private BigDecimal totalCarbs;
    private BigDecimal totalFat;
    
    public DailyNutritionSummary() {
        this.totalCalories = BigDecimal.ZERO;
        this.totalProtein = BigDecimal.ZERO;
        this.totalCarbs = BigDecimal.ZERO;
        this.totalFat = BigDecimal.ZERO;
    }
    
    public DailyNutritionSummary(LocalDate date, BigDecimal totalCalories, BigDecimal totalProtein, 
                                BigDecimal totalCarbs, BigDecimal totalFat) {
        this.date = date;
        this.totalCalories = totalCalories != null ? totalCalories : BigDecimal.ZERO;
        this.totalProtein = totalProtein != null ? totalProtein : BigDecimal.ZERO;
        this.totalCarbs = totalCarbs != null ? totalCarbs : BigDecimal.ZERO;
        this.totalFat = totalFat != null ? totalFat : BigDecimal.ZERO;
    }
    
    // Getter 和 Setter 方法
    public LocalDate getDate() {
        return date;
    }
    
    public void setDate(LocalDate date) {
        this.date = date;
    }
    
    public BigDecimal getTotalCalories() {
        return totalCalories;
    }
    
    public void setTotalCalories(BigDecimal totalCalories) {
        this.totalCalories = totalCalories != null ? totalCalories : BigDecimal.ZERO;
    }
    
    public BigDecimal getTotalProtein() {
        return totalProtein;
    }
    
    public void setTotalProtein(BigDecimal totalProtein) {
        this.totalProtein = totalProtein != null ? totalProtein : BigDecimal.ZERO;
    }
    
    public BigDecimal getTotalCarbs() {
        return totalCarbs;
    }
    
    public void setTotalCarbs(BigDecimal totalCarbs) {
        this.totalCarbs = totalCarbs != null ? totalCarbs : BigDecimal.ZERO;
    }
    
    public BigDecimal getTotalFat() {
        return totalFat;
    }
    
    public void setTotalFat(BigDecimal totalFat) {
        this.totalFat = totalFat != null ? totalFat : BigDecimal.ZERO;
    }
    
    /**
     * 添加营养数据
     */
    public void addNutrition(BigDecimal calories, BigDecimal protein, BigDecimal carbs, BigDecimal fat) {
        if (calories != null) {
            this.totalCalories = this.totalCalories.add(calories);
        }
        if (protein != null) {
            this.totalProtein = this.totalProtein.add(protein);
        }
        if (carbs != null) {
            this.totalCarbs = this.totalCarbs.add(carbs);
        }
        if (fat != null) {
            this.totalFat = this.totalFat.add(fat);
        }
    }
    
    @Override
    public String toString() {
        return "DailyNutritionSummary{" +
                "date=" + date +
                ", totalCalories=" + totalCalories +
                ", totalProtein=" + totalProtein +
                ", totalCarbs=" + totalCarbs +
                ", totalFat=" + totalFat +
                '}';
    }
}
